﻿using System;
using System.Collections.Generic;

namespace MyK3CloudCore.IOC.DataEntity
{
    /// <summary>
    /// K3元数据
    /// </summary>
    public class K3BusinessInfoResult
    {
        public K3ResponseStatus ResponseStatus { get; set; }
        public K3BusinessNeedReturn NeedReturnData { get; set; }
    }

    public class K3BusinessNeedReturn
    {
        public string Id { get; set; }
        public List<K3LanguageTranslate> Name { get; set; }
        public string MasterPKFieldName { get; set; }
        public string PkFieldName { get; set; }
        public Type PkFieldType { get; set; }
        public List<K3Table> Entrys { get; set; }
        public List<K3OperationsResult> Operations { get; set; }
    }

    public class K3OperationsResult
    {
        public int OperationId { get; set; }
        public string OperationNumber { get; set; }
        public List<K3LanguageTranslate> OperationName { get; set; }
    }

    public class K3Table
    {

        public string Id { get; set; }
        public string Key { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public List<K3LanguageTranslate> Name { get; set; }
        /// <summary>
        /// 返回此实体映射的表对应的名称
        /// </summary>
        public string TableName { get; set; }
        public string ParentKey { get; set; }
        /// <summary>
        /// 返回/设置 对应到ORM中实体类型的名称
        /// </summary>
        public string EntryName { get; set; }
        /// <summary>
        /// 分录主键字段名
        /// </summary>
        public string EntryPkFieldName { get; set; }
        /// <summary>
        /// 主键类型
        /// </summary>
        public Type PkFieldType { get; set; }
        /// <summary>
        /// 返回此实体定义的所有字段项
        /// </summary>
        public List<K3FieldResult> Fields { get; set; }
        /// <summary>
        /// 返回实体的类型，单分录/多分录
        /// </summary>
        public string EntityType { get; set; }
        /// <summary>
        /// 表示数据顺序的字段名称
        /// </summary>
        public string SeqFieldKey { get; set; }
    }

    public class K3FieldResult
    {
        /// <summary>
        /// 元数据的key
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public List<K3LanguageTranslate> Name { get; set; }
        /// <summary>
        /// 返回/设置字段在数据库中的名称
        /// </summary>
        public string FieldName { get; set; }
        /// <summary>
        /// 返回/设置 此字段在ORM中的映射，即在ORM实体中通过什么属性获取其值。
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        /// 字段存储于数据库的数据类型
		/// </summary>
        public SqlStorageType FieldType { get; set; }
        /// <summary>
        /// 返回/设置此字段所属实体的名称(TODO:是否应该改为 Entity Entity{get;})
        /// </summary>
        public string EntityKey { get; set; }
        /// <summary>
        /// 表名
        /// </summary>
        public string TableName { get; set; }
        /// <summary>
        /// 元素类型编码
        /// 值查看 K3ElementType
        /// </summary>
        public int ElementType { get; set; }
        /// <summary>
        /// 返回此字段是否必须录入
        /// </summary>
        public int MustInput { get; set; }
        /// <summary>
        /// 关联基础资料表单
        /// </summary>
        public string LookUpObjectFormId { get; set; }
        public string EnumObjectId { get; set; }
        public List<K3ExtendsField> Extends { get; set; }
        /// <summary>
        /// 该字段的控制字段，在BusinessInfo的反序列化填充
        /// </summary>
        public string ControlFieldKey { get; set; }
        public string GroupFieldTableName { get; set; }
    }

    public class K3ExtendsField
    {
        public string Value { get; set; }
        public string Caption { get; set; }
        public int Seq { get; set; }
        public bool Invalid { get; set; }
    }

    public class K3LanguageTranslate
    {
        public K3LanguageType Key { get; set; }
        public string Value { get; set; }

    }
    /// <summary>
    /// 字段数据库存储类型
    /// </summary>
    /// <remarks>
    /// SELECT * FROM systypes
    /// </remarks>
    [Flags]
    public enum SqlStorageType
    {
        SqlImage = 34,
        SqlText,
        SqlUniqueidentifier,
        SqlTinyint = 48,
        SqlSmallint = 52,
        SqlInt = 56,
        SqlSmalldatetime = 58,
        SqlReal,
        SqlMoney,
        SqlDatetime,
        SqlFloat,
        SqlnText = 99,
        SqlBit = 104,
        SqlDecimal = 106,
        SqlNumeric = 108,
        SqlSmallmoney = 122,
        SqlBigInt = 127,
        Sqlvarbinary = 165,
        Sqlvarchar = 167,
        SqlBinary = 173,
        Sqlchar = 175,
        SqlTimestamp = 189,
        SqlSysname = 231,
        Sqlnvarchar = 231,
        Sqlnchar = 239,
        SqlXML = 241
    }
}